package com.example.spinning.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.spinning.bean.DailyReport;
import com.example.spinning.bean.MaterialQuality;
import com.example.spinning.bean.MonthlyReport;
import com.example.spinning.bean.PaginationResult;
import com.example.spinning.mapper.MonthlyReportMapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.sql.Date;
import java.util.List;


@Service
@Transactional
public class MonthlyReportService {
    @Autowired
    MonthlyReportMapper monthlyReportMapper;

    //增加操作
    public int addNewMonthlyReport(MonthlyReport monthlyReport) {
       //monthlyReport.setDate(new Timestamp(System.currentTimeMillis()));
        return monthlyReportMapper.addNewMonthlyReport(monthlyReport);
    }

    //删除操作
    public boolean deleteMonthlyReportById(Long[] ids) {
        int result = monthlyReportMapper.deleteMonthlyReportById(ids);
        return result == ids.length;
    }

    //查询并分页
//    public PageInfo<MonthlyReport> findPage(Integer page, Integer size,String workshop,String month) {
//
//        MonthlyReport monthlyReport = new MonthlyReport();
//        monthlyReport.setWorkshop(workshop);
//        monthlyReport.setMonth(month);
//
//        PageHelper.startPage(page,size);
//        List<MonthlyReport> list = monthlyReportMapper.select(monthlyReport);
//        PageInfo<MonthlyReport> pageInfo = new PageInfo<>(list);
//
//        return pageInfo;
//    }
    public PaginationResult<MonthlyReport> findPage(Integer page, Integer size,String workshop,String month) {

        QueryWrapper<MonthlyReport> wrapper = new QueryWrapper();
        if (null!=workshop)
            wrapper.eq("workshop", workshop);
        if (null!=month)
            wrapper.eq("month", month);

        Page<MonthlyReport> pages = new Page<>(page,size);
        monthlyReportMapper.selectPage(pages, wrapper);
        int total = monthlyReportMapper.selectCount(wrapper);
        List<MonthlyReport> list = pages.getRecords();

        PaginationResult<MonthlyReport> pr = new PaginationResult<>();
        pr.setTotal(total);
        pr.setList(list);
        return pr;
    }
    //动态修改
    public int updateCategoryById(MonthlyReport monthlyReport){
        int result = monthlyReportMapper.updateById(monthlyReport);
        return result;
    }

}




